<template>
  <svg :style="styles" aria-hidden="true" class="svg-icon">
    <use :xlink:href="`#icon-${props.name}`"></use>
  </svg>
</template>

<script>
/**
 * svg图标
 * @param {string} name 图标名称
 * @param {number|string} size 图标大小
 * <svg-icon name=""></svg-icon>
 * */
import { computed } from 'vue';

export default {
  name: 'SvgIcon',
  props: {
    name: {
      type: String,
      default: ''
    },
    size: {
      type: Number || String,
      default: 24 || '24px'
    }
  },
  setup(props) {
    const styles = computed(() => {
      const { size } = props;
      return {
        width: !isNaN(size) ? String(size) + 'px' : size,
        height: !isNaN(size) ? String(size) + 'px' : size
      };
    });

    return {
      props,
      styles
    };
  }
};
</script>

<style></style>
